package com.atguigu.vodtest;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.vod.model.v20170321.*;
import org.apache.ibatis.builder.InitializingObject;
import org.junit.Test;

import java.util.List;

public class testVod {


    public static void main(String[] args) throws ClientException {
        deletePlay();
    }

    /*根据视频id获取视频凭证*/
    public static void getPlayAuth() throws ClientException {
        /*根据视频id获取视频播放凭证*/
        /*创建初始化对象*/
        DefaultAcsClient client = initObject.initVodClient("LTAI5tQchYebZzdABmtNB2vU", "kPF9GbrkJJE09ybEUgWSaxBursPUIq");
        /*创建获取视频凭证的request对象和response对象*/
        GetVideoPlayAuthRequest request = new GetVideoPlayAuthRequest();
        GetVideoPlayAuthResponse response = new GetVideoPlayAuthResponse();
        /*向request里面设置视频id*/
        request.setVideoId("a2666a1387f740eb8c6d33c362843835");
        /*调用初始化对象的方法，得到凭证*/
        response = client.getAcsResponse(request);
        System.out.println("视频凭证playauth:"+response.getPlayAuth());
    }

    /*根据视频id获取视频地址*/
    public static void getPlayUrl() throws ClientException {
        /*创建初始化对象*/
        DefaultAcsClient client = initObject.initVodClient("LTAI5tQchYebZzdABmtNB2vU", "kPF9GbrkJJE09ybEUgWSaxBursPUIq");
        /*创建获取视频地址resquest和response*/
        GetPlayInfoRequest request = new GetPlayInfoRequest();
        GetPlayInfoResponse response = new GetPlayInfoResponse();

        /*向request对象里面设置视频id*/
        request.setVideoId("a2666a1387f740eb8c6d33c362843835");
        /*调用初始化对象里面的方法，传递request,获取数据*/
        response = client.getAcsResponse(request);
        List<GetPlayInfoResponse.PlayInfo> playInfoList = response.getPlayInfoList();
        //播放地址
        for (GetPlayInfoResponse.PlayInfo playInfo : playInfoList) {
            System.out.print("PlayInfo.PlayURL = " + playInfo.getPlayURL() + "\n");
        }
        System.out.print("VideoBase.Title = " + response.getVideoBase().getTitle() + "\n");
    }

    /*根据视频id删除视频*/
    public static void deletePlay() throws ClientException {
        DefaultAcsClient client = initObject.initVodClient("LTAI5tQchYebZzdABmtNB2vU", "kPF9GbrkJJE09ybEUgWSaxBursPUIq");
        DeleteVideoResponse response = new DeleteVideoResponse();
        DeleteVideoRequest request = new DeleteVideoRequest();
        request.setVideoIds("a2666a1387f740eb8c6d33c362843835");
        try {
            response = client.getAcsResponse(request);
        } catch (Exception e) {
            System.out.print("ErrorMessage = " + e.getLocalizedMessage());
        }
        System.out.print("RequestId = " + response.getRequestId() + "\n");
    }


}